<!DOCTYPE html>
<html lang="en-us">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>使用yyplot绘制pubmed研究趋势 | Record life to a data scientist</title>
    <link rel="stylesheet" href="/css/style.css" />
    <link rel="stylesheet" href="/css/fonts.css" />
    <link href="//cdn.bootcss.com/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet">
  </head>

  <body>
    <nav>
    <ul class="menu">
      
      <li><a href="/">Home</a></li>
      
      <li><a href="/about/">About</a></li>
      
      <li><a href="/categories/">Categories</a></li>
      
      <li><a href="/tags/">Tags</a></li>
      
      <li><a href="/index.xml">Subscribe</a></li>
      
    </ul>
    <hr/>
    </nav>

<div class="article-meta">
<h1><span class="title">使用yyplot绘制pubmed研究趋势</span></h1>
<h2 class="author">王诗翔</h2>
<h2 class="date">2018/04/14</h2>
<p class="terms">
  
  
  Categories: <a href="/categories/r">R</a> 
  
  
  
  Tags: <a href="/tags/yyplot">yyplot</a> <a href="/tags/ggplot">ggplot</a> <a href="/tags/pubmed_trends">pubmed_trends</a> 
  
  
</p>
</div>

<main>
<p>在准备转博报告的过程中觉得有必要给一些研究添加Pubmed研究趋势，这个功能Y叔在它的公众号推过，所以我记了一下，之前在写开题报告的时候就用了下。今天又重新操作了一番，感觉非常不错，记录一下分享，说不定某些同胞需要。</p>
<p>Y叔把这个功能整合在<code>yyplot</code>包中，该包发布在<strong>Github</strong>上，所以我们需要用<code>devtools</code>包进行安装：</p>
<pre class="r"><code>install.packages(&quot;devtools&quot;)
devtools::install_github(&quot;GuangchuangYu/yyplot&quot;)</code></pre>
<p>这两个包的安装都有不少依赖包，所以大家安装的时候需要注意下。如果有解决不了的问题，欢迎在下方留言讨论。</p>
<p>Y叔的厉害之处在于它对于<code>ggplot2</code>包的理解非常深，写出包和结果对象基本都直接可以用<code>ggplot</code>展示，或者直接用<code>plot</code>绘制可以得到类似的显示效果。</p>
<p>这里以我探究非小细胞癌、小细胞癌和肺腺癌最近一些年发表的文章数为例子：</p>
<pre class="r"><code>library(yyplot)
library(ggplot2)</code></pre>
<pre class="r"><code># 键入你要搜索的关键字
term &lt;- c(&quot;Lung Adenocarcinoma&quot;, &quot;NSCLC&quot;, &quot;SCLC&quot;)
# 进行检索，指定起止年
pm   &lt;- pubmed_trend(term, year=2001:2018)
# search term: Lung Adenocarcinoma
# -&gt; querying year 2001
# -&gt; querying year 2002
# -&gt; querying year 2003
# -&gt; querying year 2004
# -&gt; querying year 2005
# -&gt; querying year 2006
# -&gt; querying year 2007
# -&gt; querying year 2008
# -&gt; querying year 2009
# -&gt; querying year 2010
# -&gt; querying year 2011
# -&gt; querying year 2012
# -&gt; querying year 2013
# -&gt; querying year 2014
# -&gt; querying year 2015
# -&gt; querying year 2016
# -&gt; querying year 2017
# -&gt; querying year 2018
# search term: NSCLC
# -&gt; querying year 2001
# -&gt; querying year 2002
# -&gt; querying year 2003
# -&gt; querying year 2004
# -&gt; querying year 2005
# -&gt; querying year 2006
# -&gt; querying year 2007
# -&gt; querying year 2008
# -&gt; querying year 2009
# -&gt; querying year 2010
# -&gt; querying year 2011
# -&gt; querying year 2012
# -&gt; querying year 2013
# -&gt; querying year 2014
# -&gt; querying year 2015
# -&gt; querying year 2016
# -&gt; querying year 2017
# -&gt; querying year 2018
# search term: SCLC
# -&gt; querying year 2001
# -&gt; querying year 2002
# -&gt; querying year 2003
# -&gt; querying year 2004
# -&gt; querying year 2005
# -&gt; querying year 2006
# -&gt; querying year 2007
# -&gt; querying year 2008
# -&gt; querying year 2009
# -&gt; querying year 2010
# -&gt; querying year 2011
# -&gt; querying year 2012
# -&gt; querying year 2013
# -&gt; querying year 2014
# -&gt; querying year 2015
# -&gt; querying year 2016
# -&gt; querying year 2017
# -&gt; querying year 2018</code></pre>
<pre class="r"><code># 绘图
plot(pm) + theme_bw()</code></pre>
<p><img src="/post/2018/2018-04-13-Pubmed_trend_for_report_files/figure-html/unnamed-chunk-3-1.svg" width="576" /></p>
<p>检索返回的结果可以直接用plot绘制，这里因为我需要添加bw主题，所以导入了ggplot2包，不然可以不使用该包</p>
<p>注意纵坐标是一个比例，该关键字发表文章数与当年文章总数的比例值，我们也可以灵活一点，只绘制发表文章数目：</p>
<pre class="r"><code>ggplot(pm, aes(x=year, y=number, color=TERM)) + 
    geom_point() + geom_line() + theme_bw() + 
    xlab(&quot;Year&quot;) + ylab(&quot;Number of Publication per Year&quot;)</code></pre>
<p><img src="/post/2018/2018-04-13-Pubmed_trend_for_report_files/figure-html/unnamed-chunk-4-1.svg" width="576" /></p>
<p>简单吧？感觉作者本身应该还有其他的设计（<a href="http://d6179ef8.wiz03.com/share/s/3m5VXU35J4UU2CZwzV3mR1pE1xo8Mo2NRk-82SJpEo2FtL25">点击阅读</a>该功能的来龙去脉），不过这已经足够我用了。有兴趣大家不妨深入探索一番。</p>
<p>比如它也可以用它来画出某个研究人员，历年来发表文章的数目，比如想看Y叔每年发多少篇文章，下面这行代码给你答案：</p>
<pre class="r"><code>pubmed_trend(&quot;Yu Guangchuang[Full Author Name]&quot;, 2010:2016)</code></pre>

</main>

  <footer>
  <script src="//yihui.name/js/math-code.js"></script>
<script async src="//cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>

<script async src="//yihui.name/js/center-img.js"></script>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-108892843-2', 'auto');
ga('send', 'pageview');
</script>

<div id="disqus_thread"></div>
<script>
    var disqus_config = function () {
    
    
    
    };
    (function() {
        if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
            document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
            return;
        }
        var d = document, s = d.createElement('script'); s.async = true;
        s.src = '//' + "codelife" + '.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>


<script src="//cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>
<script src="//cdn.bootcss.com/highlight.js/9.12.0/languages/r.min.js"></script>

<script>
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
</script>

<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({publisher: "d135f460-3fc5-4802-8169-bd08e4734a09", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>

<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=51zdev6aq4a&amp;m=0&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33" async="async"></script>
  
  <hr/>
  &copy; <a href="https://www.shixiangwang.top">Shixiang Wang</a> 2018 &ndash; 2018 保留所有版权 | <a href="https://github.com/ShixiangWang">Github</a> | <a href="https://twitter.com/ShixiangWang">Twitter</a> | <a href="https://www.jianshu.com/u/b6608e27dc74">简书</a>
  
  </footer>
  </body>
</html>

